<h1>Accelerometer</h1>

<div class="desc">Push the button below to toggle the accelerometer on and off. When on, 
the x, y, and z values for your device will be updated and displayed. You may set the 
update period in the js source.</div>

<script>
/************************************
 * Accelerometer
 ************************************/
function setAccel(e){
	$("#btnAccel").toggle(startAccel, stopAccel);
	
	//Set listener
	$(document).bind('lg_accelerometer', onAccelerate);
}
function startAccel(e){
	//Start accelerometer
	lg.accelerometer.start(.5);
}
function stopAccel(e){
	//Stop accelerometer
	lg.accelerometer.stop();
}

//On callback, set x, y, z.
function onAccelerate(e) {
	$("#x").html(Math.round(lg.accelerometer.x*100)/100);
	$("#y").html(Math.round(lg.accelerometer.y*100)/100);
	$("#z").html(Math.round(lg.accelerometer.z*100)/100);
}
</script>

<dl id="accel_data">
  <dt>X:</dt><dd id="x">&nbsp;</dd>
  <dt>Y:</dt><dd id="y">&nbsp;</dd>
  <dt>Z:</dt><dd id="z">&nbsp;</dd>
</dl>

<p>&nbsp;</p>

<a id="btnAccel" class="button">Toggle Accelerometer</a>